﻿namespace ReklamaWPF
{
    using System;
    using System.Data;
    using System.Windows;
    using System.Windows.Controls;
    using OutlookCalendar.Model;
    using System.Windows.Media;
    using System.Collections.Generic;
    using ReklamaWPF.Grids;

    internal class Functionality
    {
        public static int countrec = 100;
        public static int fromrec = 0;
        public static string CalendarDayOfWeek = "";
        public static Appointments appointments = new Appointments();
        public static Appointment appointmentSelected = null;
        public static DataBase db = new DataBase("192.168.100.100\\SQLEXPRESS", "sa", "tornado", "PASystem");

        public static void ArchiveRecord(DataGrid dataGrid1, string searchword)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            for (int i = 0; i < dataGrid1.SelectedItems.Count; i++)
            {
                DataRowView li = (DataRowView) dataGrid1.SelectedItems[i];
                string idd = li.Row.ItemArray.GetValue(0x22).ToString();
                string sql = "insert into Archyvas$Archyve ([Kompanija],[Pavadinimas originalo kalba],[Lietuviškas pavadinimas],[Trukmė 1],[Trukmė 2],[TC trukmė],[Pradzios TC],[I Įsikirtimas],[II Įsikirtimas] ,[III Įsikirtimas],[IV Įsikirtimas],[V Įsikirtimas],[VI Įsikirtimas],[VII Įsikirtimas],[VIII Įsikirtimas],[IX Įsikirtimas],[X Įsikirtimas],[XI Įsikirtimas],[Eteris 1],[Eteris 2],[Eteris 3],[Eteris 4],[Eteris 5] ,[P raidė],[Intarpai bėg#eil],[Licencijos pradžia],[Licencijos pabaiga],žanras,Metai,Režisierius,Aktoriai,Sezonas,Serija,[XII Įsikirtimas],[XIII Įsikirtimas],[XIV Įsikirtimas],[XV Įsikirtimas],KasetesNr,Salis,indeksas) values ('" + li.Row.ItemArray.GetValue(0).ToString() + "','" + li.Row.ItemArray.GetValue(1).ToString() + "','" + li.Row.ItemArray.GetValue(2).ToString() + "','" + li.Row.ItemArray.GetValue(3).ToString() + "','" + li.Row.ItemArray.GetValue(4).ToString() + "','" + li.Row.ItemArray.GetValue(5).ToString() + "','" + li.Row.ItemArray.GetValue(6).ToString() + "','" + li.Row.ItemArray.GetValue(7).ToString() + "','" + li.Row.ItemArray.GetValue(8).ToString() + "','" + li.Row.ItemArray.GetValue(9).ToString() + "','" + li.Row.ItemArray.GetValue(10).ToString() + "','" + li.Row.ItemArray.GetValue(11).ToString() + "','" + li.Row.ItemArray.GetValue(12).ToString() + "','" + li.Row.ItemArray.GetValue(13).ToString() + "','" + li.Row.ItemArray.GetValue(14).ToString() + "','" + li.Row.ItemArray.GetValue(15).ToString() + "','" + li.Row.ItemArray.GetValue(16).ToString() + "','" + li.Row.ItemArray.GetValue(17).ToString() + "','" + li.Row.ItemArray.GetValue(18).ToString() + "','" + li.Row.ItemArray.GetValue(19).ToString() + "','" + li.Row.ItemArray.GetValue(20).ToString() + "','" + li.Row.ItemArray.GetValue(21).ToString() + "','" + li.Row.ItemArray.GetValue(22).ToString() + "','" + li.Row.ItemArray.GetValue(23).ToString() + "','" + li.Row.ItemArray.GetValue(24).ToString() + "','" + li.Row.ItemArray.GetValue(26).ToString() + "','" + li.Row.ItemArray.GetValue(27).ToString() + "','" + li.Row.ItemArray.GetValue(28).ToString() + "','" + li.Row.ItemArray.GetValue(29).ToString() + "','" + li.Row.ItemArray.GetValue(30).ToString() + "','" + li.Row.ItemArray.GetValue(31).ToString() + "','" + li.Row.ItemArray.GetValue(32).ToString() + "','" + li.Row.ItemArray.GetValue(33).ToString() + "','" + li.Row.ItemArray.GetValue(35).ToString() + "','" + li.Row.ItemArray.GetValue(36).ToString() + "','" + li.Row.ItemArray.GetValue(37).ToString() + "','" + li.Row.ItemArray.GetValue(38).ToString() + "','" + li.Row.ItemArray.GetValue(39).ToString() + "','" + li.Row.ItemArray.GetValue(40).ToString() + "','" + li.Row.ItemArray.GetValue(41).ToString() + "')";
                dbc.sqlExecute(sql);
                dbc.sqlExecute("delete from Archyvas$ where id=" + idd);
            }
            DataTable tb = dbc.FindStringInTableArch(searchword, fromrec, countrec);
            dataGrid1.DataContext = tb;
        }

        public static void DeleteFromDB(DataGrid dataGrid1, string searchword)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            for (int i = 0; i < dataGrid1.SelectedItems.Count; i++)
            {
                DataRowView li = (DataRowView) dataGrid1.SelectedItems[i];
                dbc.sqlExecute("delete from Archyvas$ where id=" + li.Row.ItemArray.GetValue(0x22).ToString());
            }
            DataTable tb = dbc.FindStringInTable(searchword, fromrec, countrec);
            dataGrid1.DataContext = tb;
        }

        public static void getData(DataGrid dataGrid1)
        {
            fromrec = 0;
            countrec = 100;
            DataTable tb = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem").getTable("select * from Archyvas$ order by Kompanija,[Pavadinimas originalo kalba] asc");
            dataGrid1.DataContext = tb;
        }

        public static void getDataArch(DataGrid dataGrid1)
        {
            fromrec = 0;
            countrec = 100;
            DataTable tb = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem").getTable("select top 50 * from Archyvas$Archyve order by Kompanija,[Pavadinimas originalo kalba] asc");
            dataGrid1.DataContext = tb;
        }

       
        public static void RestorefromArchive(DataGrid dataGrid1, string searchword)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            for (int i = 0; i < dataGrid1.SelectedItems.Count; i++)
            {
                DataRowView li = (DataRowView) dataGrid1.SelectedItems[i];
                string idd = li.Row.ItemArray.GetValue(0x22).ToString();
                string sql = "insert into Archyvas$ ([Kompanija],[Pavadinimas originalo kalba],[Lietuviškas pavadinimas],[Trukmė 1],[Trukmė 2],[TC trukmė],[Pradzios TC],[I Įsikirtimas],[II Įsikirtimas] ,[III Įsikirtimas],[IV Įsikirtimas],[V Įsikirtimas],[VI Įsikirtimas],[VII Įsikirtimas],[VIII Įsikirtimas],[IX Įsikirtimas],[X Įsikirtimas],[XI Įsikirtimas],[Eteris 1],[Eteris 2],[Eteris 3],[Eteris 4],[Eteris 5] ,[P raidė],[Intarpai bėg#eil],[Licencijos pradžia],[Licencijos pabaiga],žanras,Metai,Režisierius,Aktoriai,Sezonas,Serija,[XII Įsikirtimas],[XIII Įsikirtimas],[XIV Įsikirtimas],[XV Įsikirtimas],KasetesNr,Salis,indeksas) values ('" + li.Row.ItemArray.GetValue(0).ToString() + "','" + li.Row.ItemArray.GetValue(1).ToString() + "','" + li.Row.ItemArray.GetValue(2).ToString() + "','" + li.Row.ItemArray.GetValue(3).ToString() + "','" + li.Row.ItemArray.GetValue(4).ToString() + "','" + li.Row.ItemArray.GetValue(5).ToString() + "','" + li.Row.ItemArray.GetValue(6).ToString() + "','" + li.Row.ItemArray.GetValue(7).ToString() + "','" + li.Row.ItemArray.GetValue(8).ToString() + "','" + li.Row.ItemArray.GetValue(9).ToString() + "','" + li.Row.ItemArray.GetValue(10).ToString() + "','" + li.Row.ItemArray.GetValue(11).ToString() + "','" + li.Row.ItemArray.GetValue(12).ToString() + "','" + li.Row.ItemArray.GetValue(13).ToString() + "','" + li.Row.ItemArray.GetValue(14).ToString() + "','" + li.Row.ItemArray.GetValue(15).ToString() + "','" + li.Row.ItemArray.GetValue(16).ToString() + "','" + li.Row.ItemArray.GetValue(17).ToString() + "','" + li.Row.ItemArray.GetValue(18).ToString() + "','" + li.Row.ItemArray.GetValue(19).ToString() + "','" + li.Row.ItemArray.GetValue(20).ToString() + "','" + li.Row.ItemArray.GetValue(21).ToString() + "','" + li.Row.ItemArray.GetValue(22).ToString() + "','" + li.Row.ItemArray.GetValue(23).ToString() + "','" + li.Row.ItemArray.GetValue(24).ToString() + "','" + li.Row.ItemArray.GetValue(26).ToString() + "','" + li.Row.ItemArray.GetValue(27).ToString() + "','" + li.Row.ItemArray.GetValue(28).ToString() + "','" + li.Row.ItemArray.GetValue(29).ToString() + "','" + li.Row.ItemArray.GetValue(30).ToString() + "','" + li.Row.ItemArray.GetValue(31).ToString() + "','" + li.Row.ItemArray.GetValue(32).ToString() + "','" + li.Row.ItemArray.GetValue(33).ToString() + "','" + li.Row.ItemArray.GetValue(35).ToString() + "','" + li.Row.ItemArray.GetValue(36).ToString() + "','" + li.Row.ItemArray.GetValue(37).ToString() + "','" + li.Row.ItemArray.GetValue(38).ToString() + "','" + li.Row.ItemArray.GetValue(39).ToString() + "','" + li.Row.ItemArray.GetValue(40).ToString() + "','" + li.Row.ItemArray.GetValue(41).ToString() + "')";
                dbc.sqlExecute(sql);
                dbc.sqlExecute("delete from Archyvas$Archyve  where id=" + idd);
            }
            DataTable tb = dbc.FindStringInTableArch(searchword, fromrec, countrec);
            dataGrid1.DataContext = tb;
        }

        public static void SearchInDB(DataGrid dataGrid1, string searchword)
        {
            DataTable tb = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem").FindStringInTable(searchword, fromrec, countrec);
            dataGrid1.DataContext = tb;
        }

        public static void SearchInDBArch(DataGrid dataGrid1, string searchword)
        {
            DataTable tb = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem").FindStringInTableArch(searchword, fromrec, countrec);
            dataGrid1.DataContext = tb;
        }

       

        public static void LoadAppointmentsByDate(DateTime StartDate, DateTime EndDate)
        {
            EndDate += TimeSpan.FromDays(1);
            EndDate = new DateTime(EndDate.Year, EndDate.Month, EndDate.Day, 0, 0, 0);
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            DataTable tb = dbc.getTable("select * from Programa where StartDate>='" + StartDate + "' and EndDate<'" + EndDate + "' order by StartDate");
            appointments.Clear();
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                Appointment ap = new Appointment();
                ap.Subject=tb.Rows[i]["Subject"].ToString();
                ap.StartTime=(DateTime)tb.Rows[i]["StartDate"];
                ap.EndTime = (DateTime)tb.Rows[i]["EndDate"];
                ap.Location = tb.Rows[i]["subID"].ToString();
                appointments.Add(ap);
            }
            try
                {
                    for (int y = 0; y <= appointments.Count; y++)
                    {
                        for (int i = appointments.Count-1; i >= 0; i--)
                        {
                            try
                            {
                                Appointment lastAp = appointments[i];
                                Appointment beforelastAp = appointments[i+1];
                                if ((lastAp.StartTime.Hour < 6) && (beforelastAp.StartTime.Hour >= 6) && lastAp.StartTime.ToShortDateString().Equals(beforelastAp.StartTime.ToShortDateString()))
                                {
                                    Appointment tmp = appointments[i];
                                    appointments[i] = appointments[i + 1];
                                    appointments[i + 1] = tmp;
                                }
                            }
                            catch (Exception ex) { }

                        }
                    }
                }
            catch (Exception ex) { }
        }

        public static void addAppointmentToDB(Appointment ap)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            string sql = "insert into Programa (Subject,StartDate,EndDate,subID) values ('" + ap.Subject.Replace("\r\n", "") + "','" + ap.StartTime + "','" + ap.EndTime + "','" + ap.Location + "')";
            dbc.sqlExecute(sql);
        }
        public static void removeAppointmentFromDB(Appointment ap)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            string sub = ap.Subject.Replace("\r\n", "");
            string sqlc = "delete from Programa where StartDate='" + ap.StartTime + "' and EndDate='" + ap.EndTime + "'";
           // string sqlc = "delete from Programa where Subject='" + sub + "' and StartDate='" + ap.StartTime + "' and EndDate='" + ap.EndTime + "'";
            dbc.sqlExecute(sqlc);
        }

        public static DateTime GetFirstDateOfWeek(DateTime dayInWeek, DayOfWeek firstDay)
        {
            DateTime firstDayInWeek = dayInWeek.Date;
            while (firstDayInWeek.DayOfWeek != firstDay)
                firstDayInWeek = firstDayInWeek.AddDays(-1);

            return firstDayInWeek;
        }
        public static DateTime GetLastDateOfWeek(DateTime dayInWeek, DayOfWeek firstDay)
        {
            DateTime lastDayInWeek = dayInWeek.Date;
            while (lastDayInWeek.DayOfWeek != firstDay)
                lastDayInWeek = lastDayInWeek.AddDays(1);

            lastDayInWeek -= TimeSpan.FromDays(1);
            return lastDayInWeek;
        }

        public static DataTable getDataFromArchToCombo()
        {
             DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
             DataTable tb = dbc.getTable("select [Pavadinimas originalo kalba],[Lietuviškas pavadinimas],id from Archyvas$ where ([Pavadinimas originalo kalba] is not NULL and [Lietuviškas pavadinimas] is not NULL) and [Lietuviškas pavadinimas] <>'' order by dbo.fFilterNumeric([Lietuviškas pavadinimas])");
            return tb;
        }

        public static string removeNr(string str)
        {
            string rez =str;
            int ln = str.Length - 1;
            int cnt = 0;
            for (int i = ln; i > 0; i--)
            {
                try{
                    if (str.Substring(i, 1).Equals("/"))
                    {
                        rez = str.Substring(0, i);
                        ln--;
                        cnt++;
                    }else if ((int.Parse(str.Substring(i, 1)) >= 0) && (int.Parse(str.Substring(i, 1)) <= 9))
                    {
                    rez = str.Substring(0, i);
                    ln--;
                    cnt++;
                }
                }catch(Exception ex){ break;}
            }
            if (cnt>0){
                rez = rez.Substring(0,rez.Length - 1);
            }
            return rez;
        }

        public static string getProgramDateFromDB(string id,string Subject)
        {
            string result = "";
            try
            {
                if (!id.Equals("") && !id.Equals("null"))
                {
                    DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
                    DataTable tb = dbc.getTable("select * from Archyvas$ where id=" + id);

                    string priedas = "";
                    if (Subject.Contains("(tęs.)"))
                    {
                        priedas = " (tęs.)";
                    }
                    if (Subject.Contains("(kart.)"))
                    {
                        priedas = " (kart.)";
                    }
                    if (!tb.Rows[0]["Žanras"].ToString().Equals(""))
                    {
                        if (tb.Rows[0]["Lietuviškas pavadinimas"].ToString().Equals(tb.Rows[0]["Pavadinimas originalo kalba"].ToString()))
                        {
                            result += " " + removeNr(tb.Rows[0]["Lietuviškas pavadinimas"].ToString()) + priedas + ". " + tb.Rows[0]["Žanras"].ToString();
                        }
                        else
                        {
                            string skirt = ".";
                            if (tb.Rows[0]["Žanras"].ToString().Substring(tb.Rows[0]["Žanras"].ToString().Length - 1).Contains("."))
                                skirt = "";
                            string pav = removeNr(tb.Rows[0]["Lietuviškas pavadinimas"].ToString());
                            if (pav.Contains("("))
                            {
                                pav = pav.Replace(" (", "“ (");
                            }
                            else
                            {
                                pav = pav + "“";
                            }
                            result += " " + "„" + pav + priedas + ". " + tb.Rows[0]["Žanras"].ToString() + skirt;

                        }
                    }
                    else
                    {
                        result += " " + removeNr(tb.Rows[0]["Lietuviškas pavadinimas"].ToString()) + priedas;
                    }
                    if (!tb.Rows[0]["Režisierius"].ToString().Equals(""))
                    {
                        result += ". " + tb.Rows[0]["Režisierius"].ToString();
                    }
                    if (!tb.Rows[0]["Aktoriai"].ToString().Equals(""))
                    {
                        result += ". " + tb.Rows[0]["Aktoriai"].ToString();
                    }
                    if (!tb.Rows[0]["Salis"].ToString().Equals(""))
                    {
                        result += ". " + tb.Rows[0]["Salis"].ToString();
                    }
                    if (!tb.Rows[0]["Metai"].ToString().Equals(""))
                    {
                        result += ". " + tb.Rows[0]["Metai"].ToString();
                    }
                    if (!tb.Rows[0]["indeksas"].ToString().Equals(""))
                    {
                        result += ". " + tb.Rows[0]["indeksas"].ToString().Replace("(", "").Replace(")", "");
                    }
                    result = result.Replace("..", ".");
                }
            }
            catch (Exception ex) { }
            return result;
        }


        public static string getTinklelismDateFromDB(string id,string Subject)
        {
            string result = "";
            if (!id.Equals("") && !id.Equals("null"))
            {
                string priedas = "";
                if (Subject.Contains("(tęs.)"))
                {
                    priedas = " (tęs.)";
                }
                if (Subject.Contains("(kart.)"))
                {
                    priedas = " (kart.)";
                }
                DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
                DataTable tb = dbc.getTable("select * from Archyvas$ where id=" + id);
               
                    if (!tb.Rows[0]["Lietuviškas pavadinimas"].ToString().Equals(tb.Rows[0]["Pavadinimas originalo kalba"].ToString()))
                    {
                        result = tb.Rows[0]["Lietuviškas pavadinimas"].ToString() + priedas+ ".   " + tb.Rows[0]["Pavadinimas originalo kalba"].ToString() + ". " + tb.Rows[0]["Kompanija"].ToString();
                    }
                    else
                    {
                        result = tb.Rows[0]["Pavadinimas originalo kalba"].ToString()+priedas;
                    }
                
                
            }
            return result;
        }

        public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
        {
            if (depObj != null)
            {
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                {
                    DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
                    if (child != null && child is T)
                    {
                        yield return (T)child;
                    }

                    foreach (T childOfChild in FindVisualChildren<T>(child))
                    {
                        yield return childOfChild;
                    }
                }
            }
        }

        public static string checkBoxValue(CheckBox chk){
            string rez = "0";
            if (chk.IsChecked == true) { rez = "1"; }
            return rez;
        }


        public static bool insertAdvIntoDB(AdvertisingAdd iw)
        {
            bool commited = false;
            string sql;
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");

            string sqll = "";
            sql = "insert into AdvertisingData (Advertiser_id,free,Compaign_id,Program_id,BlockPos,Date,Time,GRP_price,GRP,Clip_id,Rejected) values (" + iw.AdvId + "," + checkBoxValue(iw.checkBox1) + "," + iw.ComId + "," + iw.ProgId + "," + iw.textBox2.Text + ",'" + iw.datePicker1.Text + "','" + iw.textBox3.Text + "','" + iw.textBox4.Text + "','" + iw.textBox5.Text + "'," + iw.ClipId + "," + checkBoxValue(iw.checkBox2) + ")";
            commited = dbc.sqlExecute(sql);
            return commited;
        }

        internal static void updateAdvIntoDB(AdvertisingAdd iw, DevExpress.Xpf.Grid.GridControl dataGrid1, string searchword, string id)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            string sql = "select *,case BlockPos when 1 then 1 else case BlockPos when 2 then 2 else case BlockPos when 99 then 99 else 5 end  end  end AS 'PlaceInBlock',MONTH(Date) AS 'Month',DatePart(HOUR,Duration) * 3600 + DatePart(MINUTE, Duration) * 60 + DatePart(SECOND, Duration) AS 'ShortDuration' from AdvertisingData ad left join Advertisers adv on Advertiser_id=adv.id left join Campaigns cpg on Compaign_id=cpg.id left join Archyvas$ prg on Program_id=prg.id left join Clips on Clip_Id=Clips.id left join Blocks on [Time]>[Time_from] and [Time]<[Time_to] where ad.id=" + id;
            DataTable tb = dbc.getTable(sql);
            if (tb.Rows.Count > 0)
            {
                iw.Title = "Įrašo redagavimas";
                iw.AdvId = tb.Rows[0]["Advertiser_id"].ToString();
                iw.textBox2.Text = tb.Rows[0]["BlockPos"].ToString();
                iw.datePicker1.DisplayDate = DateTime.Parse(tb.Rows[0]["Date"].ToString());
                iw.datePicker1.Text = tb.Rows[0]["Date"].ToString();
                iw.textBox3.Text = tb.Rows[0]["Time"].ToString();
                iw.textBox4.Text = tb.Rows[0]["GRP_price"].ToString();
                iw.textBox5.Text = tb.Rows[0]["GRP"].ToString();
                iw.ClipId = tb.Rows[0]["Clip_id"].ToString();
                iw.ComId = tb.Rows[0]["Compaign_id"].ToString();
                iw.ProgId = tb.Rows[0]["Program_id"].ToString();
                iw.checkBox1.IsChecked = Boolean.Parse(tb.Rows[0]["free"].ToString());
                iw.checkBox2.IsChecked = Boolean.Parse(tb.Rows[0]["Rejected"].ToString());
                if (iw.ShowDialog() == true)
                {
                    sql = "UPDATE AdvertisingData SET Advertiser_id = " + iw.AdvId + ",free = " + checkBoxValue(iw.checkBox1) + ",Compaign_id = " + iw.ComId + ",Program_id =" + iw.ProgId + ",BlockPos = " + iw.textBox2.Text + ",Date = '" + iw.datePicker1.Text + "',Time = '" + iw.textBox3.Text + "',GRP_price = '" + iw.textBox4.Text + "',GRP = '" + iw.textBox5.Text + "',Clip_id = " + iw.ClipId+ ",Rejected = " + checkBoxValue(iw.checkBox2) + " WHERE id=" + id;
                    dbc.sqlExecute(sql);
                   //tb = dbc.FindStringInTable(searchword, fromrec, countrec);
                   // dataGrid1.DataContext = tb;
                }
            }
        }

        public static bool insertBlockIntoDB(BlockAdd iw)
        {
            bool commited = false;
            string sql;
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");

            string sqll = "";
            sql = "insert into Blocks (Block_Name,Time_from,Time_to,Time_pos,Period_H,Comments,ValidUpTo) values ('" + iw.textBox1.Text + "','" + iw.textBox2.Text + "','" + iw.textBox3.Text + "','" + iw.textBox4.Text + "','" + iw.textBox5.Text + "','" + iw.textBox6.Text + "','" + iw.datePicker1.Text + "')";
            commited = dbc.sqlExecute(sql);
            return commited;
        }

        internal static void updateBlockIntoDB(BlockAdd iw, DevExpress.Xpf.Grid.GridControl dataGrid1, string searchword, string id)
        {
            DataBase dbc = new DataBase(@"192.168.100.100\SQLEXPRESS", "sa", "tornado", "PASystem");
            string sql = "select * from Blocks where id=" + id;
            DataTable tb = dbc.getTable(sql);
            if (tb.Rows.Count > 0)
            {
                iw.Title = "Įrašo redagavimas";
                iw.textBox1.Text = tb.Rows[0]["Block_Name"].ToString();
                iw.textBox2.Text = tb.Rows[0]["Time_from"].ToString();
                iw.textBox3.Text = tb.Rows[0]["Time_to"].ToString();
                iw.textBox4.Text = tb.Rows[0]["Time_pos"].ToString();
                iw.textBox5.Text = tb.Rows[0]["Period_H"].ToString();
                iw.textBox6.Text = tb.Rows[0]["Comments"].ToString();
                iw.datePicker1.DisplayDate = DateTime.Parse(tb.Rows[0]["ValidUpTo"].ToString());
                iw.datePicker1.Text = tb.Rows[0]["ValidUpTo"].ToString();
                if (iw.ShowDialog() == true)
                {
                    sql = "UPDATE Blocks SET Block_Name ='" + iw.textBox1.Text + "',Time_from ='" + iw.textBox2.Text + "',Time_to ='" + iw.textBox3.Text + "',Time_pos ='" + iw.textBox4.Text + "',Period_H ='" + iw.textBox5.Text + "',Comments = '" + iw.textBox6.Text  + "',ValidUpTo = '" + iw.datePicker1.Text + "' WHERE id=" + id;
                    dbc.sqlExecute(sql);
                    //tb = dbc.FindStringInTable(searchword, fromrec, countrec);
                    // dataGrid1.DataContext = tb;
                }
            }
        }


        /* VBA scripts
           
         Sub isklotine()

     Dim ix As Integer
  Dim e, epr, x As Integer
  Dim str, pavadinimas, st As String
  Dim data As String
  Dim kl As Integer
  Dim y As Long
  Dim WS As Worksheet
  kiek = 0
  
    ix = 0
  Set WS = ActiveSheet
  For i = 8 To 500
    If (WS.Cells(i, 6) = "") Then
      ix = i
      Exit For
    End If
  Next i
  'Dim WS As Worksheet
 'Set WS = Sheets.Add
 data = Format(ActiveSheet.Cells(3, 2), "yyyy-mm-dd")
 pavadinimas = "reklama " + data
  Sheets.Add.Name = pavadinimas
  'Range(B0, B200).Select
  'Selection.NumberFormat = "hh:mm:ss"
  e = 2
  i = 8
  x = 1
  Sheets(pavadinimas).Cells(1, 4) = WS.Cells(3, 2)
  Range("D1").Select
  Selection.NumberFormat = "yyyy-mm-dd;@"
  While (i < ix - 1)
    
    n = 1
    ixn = i
    Sheets(pavadinimas).Cells(e, 1) = x
    Sheets(pavadinimas).Cells(e, 2) = WS.Cells(3, 2)
    Sheets(pavadinimas).Cells(e, 3) = WS.Cells(ixn, 2)
    Sheets(pavadinimas).Cells(e, 4) = "REKLAMA"
    Sheets(pavadinimas).Cells(e, 5) = 0.000129444444
    Sheets(pavadinimas).Cells(e, 7) = n
    epr = e
    e = e + 1
    n = n + 1
    x = x + 1
    
    Do
    Sheets(pavadinimas).Cells(e, 2) = WS.Cells(3, 2)
    Sheets(pavadinimas).Cells(e, 3) = WS.Cells(ixn, 2)
    Sheets(pavadinimas).Cells(e, 4) = WS.Cells(i, 5)
    Sheets(pavadinimas).Cells(e, 5) = WS.Cells(i, 6)
    Sheets(pavadinimas).Cells(e, 7) = n
    e = e + 1
    n = n + 1
    i = i + 1
    Loop Until (WS.Cells(i, 5) = "")
    
    Sheets(pavadinimas).Cells(e, 2) = WS.Cells(3, 2)
    Sheets(pavadinimas).Cells(e, 3) = WS.Cells(ixn, 2)
    Sheets(pavadinimas).Cells(e, 4) = "REKLAMA"
    Sheets(pavadinimas).Cells(e, 5) = 0.000129444444
    
    Sheets(pavadinimas).Cells(e, 7) = 99
    e = e + 1
    
    str = "=SUM(E" & epr & ":E" & (e - 1) & ")"
    Sheets(pavadinimas).Cells(e, 5).Value = str
    Range("E" & e).Select
    Selection.Font.Bold = True
    e = e + 1
    i = i + 1
    
    Range("B" & epr & ":G" & (e - 1)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlMedium
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    
 Wend
   Columns("A:A").Select
    Selection.Font.Bold = True
    Columns("B:B").Select
    Selection.NumberFormat = "m/d/yyyy"
    Columns("E:E").Select
    Selection.NumberFormat = "[$-F400]h:mm:ss AM/PM"
    Columns("C:C").Select
    Selection.NumberFormat = "[$-F400]h:mm:ss AM/PM"
    Columns("D:D").ColumnWidth = 37.29

  'Sheets(pavadinimas).Range("E:E").Columns.ColumnWidth = 285
End Sub
         * 
         * 
Sub pozicijabloke()
'
' isklotine Macro
' Macro recorded 2009.04.03 by Andrius Valionis
'

'
     Dim ix As Integer
  Dim e, epr, x As Integer
  Dim str, pavadinimas, st As String
  Dim data As String
  Dim kl As Integer
  Dim y As Long
  Dim WS As Worksheet
  kiek = 0
  y = 2
  While (Sheets("Duomenys").Cells(y, 13) <> "")
    If IsNumeric(Sheets("Duomenys").Cells(y, 4)) = False Then
       kl = kel(Sheets("Duomenys").Cells(y, 4))
       If kl > 0 Then
       Sheets("Duomenys").Cells(y, 4) = reiksme(kl)
       Else
5:     sk = InputBox("Rasta '" + Sheets("Duomenys").Cells(y, 4) + "' iveskite atitikmená:", "Ávedimas", "")
       If IsNumeric(sk) Then
         st = sk
        
         f = ideti(Sheets("Duomenys").Cells(y, 4), st)
         Sheets("Duomenys").Cells(y, 4) = sk
       Else
         GoTo 5
       End If
       End If
    End If
    y = y + 1
  Wend
End Sub

Function kel(eil As String) As Integer
  kel = 0
  For i = 1 To kiek
    If eil = raide(i) Then
      kel = i
    End If
  Next i
End Function

Function ideti(eil, reiks As String) As Boolean
  kiek = kiek + 1
  raide(kiek) = eil
  reiksme(kiek) = reiks
  ideti = True
End Function

Sub SkaiciuotiVirs()
  Dim NewBook As Workbook
  Dim CurBook As Workbook

  Dim e, epr, x, xx As Integer
  Dim str, pavadinimas, st, st1, st2 As String
  Dim data As String
  Dim kl, i1, i2, ix As Integer
  Dim y As Long
  Dim WS As Worksheet
  Set CurBook = ActiveWorkbook
  kiek = 0
  ix = 0
  y = 3
  
  If TikrintiFiltrus() = False Then
  xx = CurBook.Sheets("Duomenys").Cells.Find(What:=" ", After:=CurBook.Sheets("Duomenys").Range("A1"), searchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  
  While (CurBook.Sheets("ivedimui").Cells(y, 10) <> "")
    st = CurBook.Sheets("ivedimui").Cells(y, 17)
    st1 = CurBook.Sheets("ivedimui").Cells(y, 18)
    st2 = CurBook.Sheets("ivedimui").Cells(y, 19)
    CurBook.Sheets("ivedimui").Cells(1, 20) = CurBook.Sheets("ivedimui").Cells(y, 19) '"'" & st2
    CurBook.Sheets("ivedimui").Cells(1, 21) = CurBook.Sheets("ivedimui").Cells(y, 18) '"'" & st1
    On Error Resume Next
    i1 = CurBook.Sheets("ivedimui").Cells(1, 23).Value
    On Error Resume Next
    i2 = CurBook.Sheets("ivedimui").Cells(1, 22).Value
    CurBook.Sheets("ivedimui").Cells(1, 24) = CurBook.Sheets("reklama pagal dienas").Cells(i1 + 7, i2 + 1)
    CurBook.Sheets("ivedimui").Cells(1, 25) = CurBook.Sheets("ivedimui").Cells(1, 24).Value + st
    lyg1 = CurBook.Sheets("ivedimui").Cells(1, 25)
    lyg2 = CurBook.Sheets("reklama pagal dienas").Cells(2, 4)
    If (CurBook.Sheets("ivedimui").Cells(1, 25) > CurBook.Sheets("reklama pagal dienas").Cells(2, 4)) Then
        ix = ix + 1
        If (ix = 1) Then
         'Set WS = Sheets.Add
         Set NewBook = Workbooks.Add
         NewBook.Sheets.Add.Name = "atsauktos" & Date
        End If
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 1) = CurBook.Sheets("ivedimui").Cells(y, 1)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 2) = CurBook.Sheets("ivedimui").Cells(y, 2)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 3) = CurBook.Sheets("ivedimui").Cells(y, 3)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 4) = CurBook.Sheets("ivedimui").Cells(y, 4)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 5) = CurBook.Sheets("ivedimui").Cells(y, 5)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 6) = CurBook.Sheets("ivedimui").Cells(y, 6)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 7) = CurBook.Sheets("ivedimui").Cells(y, 7)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 8) = CurBook.Sheets("ivedimui").Cells(y, 8)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 9) = CurBook.Sheets("ivedimui").Cells(y, 9)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 10) = CurBook.Sheets("ivedimui").Cells(y, 10)
        NewBook.Sheets("atsauktos" & Date).Cells(ix, 11) = CurBook.Sheets("ivedimui").Cells(y, 11)
        'Sheets("atsauktos" & Date).Cells(ix, 12) = Sheets("ivedimui").Cells(y, 12)
        'Sheets("atsauktos" & Date).Cells(ix, 13) = Sheets("ivedimui").Cells(y, 13)
        'Sheets("atsauktos" & Date).Cells(ix, 14) = Sheets("ivedimui").Cells(y, 14)
        'Sheets("atsauktos" & Date).Cells(ix, 15) = Sheets("ivedimui").Cells(y, 15)
        'Sheets("atsauktos" & Date).Cells(ix, 16) = Sheets("ivedimui").Cells(y, 16)
        'Sheets("atsauktos" & Date).Cells(ix, 17) = Sheets("ivedimui").Cells(y, 17)
        'Sheets("atsauktos" & Date).Cells(ix, 18) = Sheets("ivedimui").Cells(y, 18)
        'Sheets("atsauktos" & Date).Cells(ix, 19) = Sheets("ivedimui").Cells(y, 19)
        NewBook.Sheets("atsauktos" & Date).Select
        Columns("F:F").Select
        Selection.NumberFormat = "yyyy/mm/dd;@"
        Columns("G:G").Select
        Selection.NumberFormat = "hh:mm:ss;@"
        Range("I21").Select
        
        xx = xx + 1
        CurBook.Sheets("Duomenys").Cells(xx, 1) = CurBook.Sheets("ivedimui").Cells(y, 1)
        CurBook.Sheets("Duomenys").Cells(xx, 2) = CurBook.Sheets("ivedimui").Cells(y, 2)
        CurBook.Sheets("Duomenys").Cells(xx, 3) = CurBook.Sheets("ivedimui").Cells(y, 3)
        CurBook.Sheets("Duomenys").Cells(xx, 4) = CurBook.Sheets("ivedimui").Cells(y, 4)
        CurBook.Sheets("Duomenys").Cells(xx, 5) = CurBook.Sheets("ivedimui").Cells(y, 5)
        CurBook.Sheets("Duomenys").Cells(xx, 6) = CurBook.Sheets("ivedimui").Cells(y, 6)
        CurBook.Sheets("Duomenys").Cells(xx, 7) = CurBook.Sheets("ivedimui").Cells(y, 7)
        CurBook.Sheets("Duomenys").Cells(xx, 8) = CurBook.Sheets("ivedimui").Cells(y, 8)
        CurBook.Sheets("Duomenys").Cells(xx, 9) = CurBook.Sheets("ivedimui").Cells(y, 9)
        CurBook.Sheets("Duomenys").Cells(xx, 10) = CurBook.Sheets("ivedimui").Cells(y, 10)
        CurBook.Sheets("Duomenys").Cells(xx, 11) = CurBook.Sheets("ivedimui").Cells(y, 11)
        CurBook.Sheets("Duomenys").Cells(xx, 12) = CurBook.Sheets("ivedimui").Cells(y, 12)
        CurBook.Sheets("Duomenys").Cells(xx, 13) = CurBook.Sheets("ivedimui").Cells(y, 13)
        CurBook.Sheets("Duomenys").Cells(xx, 14) = CurBook.Sheets("ivedimui").Cells(y, 14)
        CurBook.Sheets("Duomenys").Cells(xx, 15) = CurBook.Sheets("ivedimui").Cells(y, 15)
        CurBook.Sheets("Duomenys").Cells(xx, 16) = CurBook.Sheets("ivedimui").Cells(y, 16)
        CurBook.Sheets("Duomenys").Cells(xx, 17) = CurBook.Sheets("ivedimui").Cells(y, 17)
        CurBook.Sheets("Duomenys").Cells(xx, 18) = CurBook.Sheets("ivedimui").Cells(y, 18)
        CurBook.Sheets("Duomenys").Cells(xx, 19) = CurBook.Sheets("ivedimui").Cells(y, 19)
        CurBook.Sheets("Duomenys").Cells(xx, 12) = "Taip"
    Else
      'Sheets("Duomenys").Cells(y, 12) = ""
        xx = xx + 1
        CurBook.Sheets("Duomenys").Cells(xx, 1) = CurBook.Sheets("ivedimui").Cells(y, 1)
        CurBook.Sheets("Duomenys").Cells(xx, 2) = CurBook.Sheets("ivedimui").Cells(y, 2)
        CurBook.Sheets("Duomenys").Cells(xx, 3) = CurBook.Sheets("ivedimui").Cells(y, 3)
        CurBook.Sheets("Duomenys").Cells(xx, 4) = CurBook.Sheets("ivedimui").Cells(y, 4)
        CurBook.Sheets("Duomenys").Cells(xx, 5) = CurBook.Sheets("ivedimui").Cells(y, 5)
        CurBook.Sheets("Duomenys").Cells(xx, 6) = CurBook.Sheets("ivedimui").Cells(y, 6)
        CurBook.Sheets("Duomenys").Cells(xx, 7) = CurBook.Sheets("ivedimui").Cells(y, 7)
        CurBook.Sheets("Duomenys").Cells(xx, 8) = CurBook.Sheets("ivedimui").Cells(y, 8)
        CurBook.Sheets("Duomenys").Cells(xx, 9) = CurBook.Sheets("ivedimui").Cells(y, 9)
        CurBook.Sheets("Duomenys").Cells(xx, 10) = CurBook.Sheets("ivedimui").Cells(y, 10)
        CurBook.Sheets("Duomenys").Cells(xx, 11) = CurBook.Sheets("ivedimui").Cells(y, 11)
        CurBook.Sheets("Duomenys").Cells(xx, 12) = CurBook.Sheets("ivedimui").Cells(y, 12)
        CurBook.Sheets("Duomenys").Cells(xx, 13) = CurBook.Sheets("ivedimui").Cells(y, 13)
        CurBook.Sheets("Duomenys").Cells(xx, 14) = CurBook.Sheets("ivedimui").Cells(y, 14)
        CurBook.Sheets("Duomenys").Cells(xx, 15) = CurBook.Sheets("ivedimui").Cells(y, 15)
        CurBook.Sheets("Duomenys").Cells(xx, 16) = CurBook.Sheets("ivedimui").Cells(y, 16)
        CurBook.Sheets("Duomenys").Cells(xx, 17) = CurBook.Sheets("ivedimui").Cells(y, 17)
        CurBook.Sheets("Duomenys").Cells(xx, 18) = CurBook.Sheets("ivedimui").Cells(y, 18)
        CurBook.Sheets("Duomenys").Cells(xx, 19) = CurBook.Sheets("ivedimui").Cells(y, 19)
        
    End If
1:      y = y + 1
  Wend
  y = y - 1

  copyTable NewBook, CurBook
  

  MsgBox "Baigta!"
  Else
    MsgBox "Nuimkite filtrà!"
  End If
End Sub


Sub copyTable(book As Workbook, crboos As Workbook)
  Dim x1, x2, x3, x4 As Integer
  Dim ix, ix1 As Double
  

  On Error Resume Next

  If Not book.Sheets("atsauktos" & Date) Is Nothing Then
  
  x1 = book.Sheets("atsauktos" & Date).Cells.Find(What:=" ", After:=book.Sheets("atsauktos" & Date).Range("A1"), searchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
  
    crboos.Activate
    crboos.Sheets("reklama pagal dienas").Select
    crboos.Sheets("reklama pagal dienas").Rows("7:38").Select
    Selection.Copy
 
    book.Activate
    book.Sheets("atsauktos" & Date).Select
    book.Sheets("atsauktos" & Date).Rows((x1 + 5) & ":" & (x1 + 5)).Select
    book.Sheets("atsauktos" & Date).Paste
    book.Selection.FormatConditions.Delete
    book.FormatConditions.Delete
    'book.Selection.
    book.Sheets("atsauktos" & Date).Columns("A:A").ColumnWidth = 12.43
    
    book.Sheets("atsauktos" & Date).Range("A" & (x1 + 5)).Select
    Application.CutCopyMode = False
    Selection.ClearContents
    
    For i = 2 To 21
      For y = (x1 + 6) To (x1 + 5 + 38)
         ix = book.Sheets("atsauktos" & Date).Cells(y, i)
         ix1 = crboos.Sheets("reklama pagal dienas").Range("B1").Value2
         If ix > ix1 Then
            book.Sheets("atsauktos" & Date).Cells(y, i) = "netelpa"
         Else
           book.Sheets("atsauktos" & Date).Cells(y, i) = ""
         End If
      Next y
    Next i
    
    book.Sheets("atsauktos" & Date).Range("U" & (x1 + 5) & ":U" & (x1 + 36)).Select
    Selection.Delete Shift:=xlToLeft
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    Selection.Borders(xlEdgeBottom).LineStyle = xlNone
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    book.Sheets("atsauktos" & Date).Range("A1").Select
    
     End If
    
End Sub

Function Tikrinti(i As Integer) As Integer
Dim xx, e As Integer
xx = Sheets("Duomenys").Cells.Find(What:="", After:=Sheets("Duomenys").Range("A1"), searchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Tikrinti = 0
For e = 1 To xx
   If Sheets("Duomenys").Cells(e, 1) = Sheets("Atsaukimai").Cells(i, 1) Then
   If Sheets("Duomenys").Cells(e, 2) = Sheets("Atsaukimai").Cells(i, 2) Then
   If Sheets("Duomenys").Cells(e, 3) = Sheets("Atsaukimai").Cells(i, 3) Then
   If Sheets("Duomenys").Cells(e, 4) = Sheets("Atsaukimai").Cells(i, 4) Then
   If Sheets("Duomenys").Cells(e, 5) = Sheets("Atsaukimai").Cells(i, 5) Then
   If Sheets("Duomenys").Cells(e, 6) = Sheets("Atsaukimai").Cells(i, 6) Then
   If Sheets("Duomenys").Cells(e, 7) = Sheets("Atsaukimai").Cells(i, 7) Then
   If Sheets("Duomenys").Cells(e, 8) = Sheets("Atsaukimai").Cells(i, 8) Then
   If Sheets("Duomenys").Cells(e, 9) = Sheets("Atsaukimai").Cells(i, 9) Then
   If Sheets("Duomenys").Cells(e, 10) = Sheets("Atsaukimai").Cells(i, 10) Then
   If Sheets("Duomenys").Cells(e, 11) = Sheets("Atsaukimai").Cells(i, 11) Then
   If Not Sheets("Duomenys").Cells(e, 12) = "Taip" Then
     Tikrinti = e
     Exit Function
   Else
      Tikrinti = -10
   End If
   End If
   End If
   End If
   End If
   End If
   End If
   End If
   End If
   End If
   End If
   End If
Next e
End Function

Sub Atsaukimai()
Dim xx, i As Integer
xx = Sheets("Atsaukimai").Cells.Find(What:="", After:=Sheets("Atsaukimai").Range("A1"), searchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For i = 2 To xx - 1
  ix = Tikrinti(i)
  If ix > 0 Then
    Sheets("Duomenys").Cells(ix, 12) = "Taip"
    Sheets("Atsaukimai").Cells(i, 12) = "Rastas"
  ElseIf ix = -10 Then
    Sheets("Atsaukimai").Cells(i, 12) = "Rastas"
  Else
    Sheets("Atsaukimai").Cells(i, 12) = "Nerastas"
  End If
Next i
End Sub
       */
    }
}

